ViewContext.RouteData.Values["action"] is null on server... works fine on local machine

Posted by rksprst on Stack Overflow See other posts from Stack Overflow or by rksprst
Published on 2009-08-09T20:55:22Z Indexed on 2010/04/02 8:03 UTC
Read the original article Hit count: 876

I'm having a weird issue where ViewContext.RouteData.Values["action"] is null on my staging server, but works fine on my dev machine (asp.net development server).

The code is simple:

public string CheckActiveClass(string actionName)
    {
        string text = "";
        if (ViewContext.RouteData.Values["action"].ToString() == actionName)
        {
            text = "selected";
        }
        return text;
    }

I get the error on the ViewContext.RouteData.Values["action"] line. The error is:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Any help is appreciated. Thanks in advance.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about ASP.NET